//
//  SingleRadioTableViewCell.m
//  news
//
//  Created by lanou on 15/12/17.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "SingleRadioTableViewCell.h"
#import "SingleRadioListModel.h"

@implementation SingleRadioTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        CGFloat imageWidth = (kWidth - 20) / 3.0;
        self.radioImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, imageWidth, imageWidth)];
        self.radioImage.backgroundColor = [UIColor grayColor];
        [self setImageViewWithLayer:self.radioImage];
        [self.contentView addSubview:self.radioImage];
        
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageWidth + 2 * 10 , self.bounds.size.height / 2.0, kWidth - imageWidth - 10 * 3, 20)];
        self.titleLabel.font = [UIFont systemFontOfSize:15];
        [self.contentView addSubview:self.titleLabel];
        
        self.describeLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageWidth + 2 * 10 , self.bounds.size.height / 2.0 + 20, kWidth - imageWidth - 10 * 3, 50)];
        self.describeLabel.numberOfLines = 0;
        self.describeLabel.font = [UIFont systemFontOfSize:16];
        self.describeLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:self.describeLabel];
        
        self.iconPlayCount = [[UIImageView alloc] initWithFrame:CGRectMake(imageWidth + 2 * 10, self.bounds.size.height / 2.0 + 20 + 50, 20, 20)];
        self.iconPlayCount.image = [UIImage imageNamed:@"c9cb8b3032"];
        [self.contentView addSubview:self.iconPlayCount];
        
        self.playCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(imageWidth + 2 * 10 + 25, self.bounds.size.height / 2.0 + 20 + 50, kWidth - imageWidth - 4 * 10 - 20, 20)];
        self.playCountLabel.textColor = [UIColor grayColor];
        self.playCountLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.playCountLabel];
        
    }
    return self;
}

- (void)setSingleRadioListModel:(SingleRadioListModel *)singleRadioListModel {
    
    if (_singleRadioListModel != singleRadioListModel) {
        _singleRadioListModel = singleRadioListModel;
        
        [self.radioImage setImageWithURL:[NSURL URLWithString:_singleRadioListModel.radio[@"imgsrc"]] placeholderImage:nil];
        
        self.titleLabel.text = _singleRadioListModel.tname;
        
        self.describeLabel.text = _singleRadioListModel.radio[@"title"];
        
        NSString *string = [NSString stringWithFormat:@"%ld",_singleRadioListModel.playCount];
        NSString *string1 = [string substringToIndex:3];
        NSString *resultStr = [[[string1 stringByAppendingString:@"."] stringByAppendingString:[string substringWithRange:NSMakeRange(3, 1)]] stringByAppendingString:@"万"];
        self.playCountLabel.text = resultStr;

    }
    
}

// 设置图片为圆形
- (void)setImageViewWithLayer:(UIImageView *)imageView {
    imageView.layer.masksToBounds = YES;
    imageView.layer.borderWidth = 2;
    imageView.layer.cornerRadius = imageView.bounds.size.height / 2;
    imageView.layer.borderColor = [[UIColor grayColor] CGColor];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
